package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import com.sky.result.PageResult;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     * @param username
     * @return
     */
    //获取用户数据
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    //修改错误次数
    @Update("update employee set errnums=#{errnum} where id=#{userid}")
    int setErrnums(int errnum,long userid);

    //修改用户状态码
    @Update("update employee set status=#{status} where id=#{userid}")
    int setStatus(int status,long userid);

    /**
     * 添加员工
     * @param employee
     */
    @Insert("insert into employee(name, username, password, phone, sex, id_number, status, errnums, create_time, update_time, create_user, update_user) " +
            "values " +
            "(#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{status},#{errnums},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @AutoFill(value=OperationType.INSERT)//设置注解类型为insert
    void insert(Employee employee);

    /**
     * 获取员工列表
     * @param employeePageQueryDTO
     * @return
     */
    Page<Employee> getPage(EmployeePageQueryDTO employeePageQueryDTO);

    /**
     * 修改员工信息
     * @param employee
     */
    @AutoFill(value=OperationType.UPDATE)//设置注解类型为update
    void updateData(Employee employee);

    /**
     * 根据id查询用户信息
     * @param id
     * @return
     */
    @Select("select * from employee where id=#{id}")
    Employee getById(Long id);
}
